package com.cloud.system.controller;

import com.cloud.common.domain.Result;
import com.cloud.controller.BaseController;
import com.cloud.entity.SysUserAuth;
import com.cloud.entity.vo.AuthParam;
import com.cloud.user_info.service.ISysUserAuthService;
import com.cloud.utils.ToolUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账户第三方授权
 *
 * @author yzj
 */
@Tag(name = "用户授权")
@RestController
@RequestMapping("/system/auth")
public class SysUserAuthController extends BaseController {

    @Autowired
    private ISysUserAuthService userAuthService;

    @Operation(summary = "查询用户授权列表")
    @GetMapping("/allList")
    public Result allList(SysUserAuth userAuth) {
        List<SysUserAuth> list = userAuthService.selectUserAuthList(userAuth);
        return Result.success("查询成功", list);
    }

    @Operation(summary = "添加用户授权信息")
    @PostMapping("/insert")
    public Result insert(@RequestBody SysUserAuth userAuth) {
        return userAuthService.insertUserAuth(userAuth);
    }

    @Operation(summary = "修改用户授权信息")
    @PostMapping("/update")
    public Result update(@RequestBody SysUserAuth userAuth) {
        return userAuthService.updateUserAuth(userAuth);
    }

    @Operation(summary = "删除用户授权信息")
    @Parameter(name = "authIds", description = "授权ID[多个用,隔开]")
    @PostMapping("/remove")
    public Result remove(String authIds) {
        List<Long> list = ToolUtils.setIdsToList(authIds);
        return toResult(userAuthService.deleteUserAuthById(list));
    }

    @Operation(summary = "Feign内部调用(根据类型获取授权ID列表)")
    @RequestMapping(value = "/getUserAuthIds", method = {RequestMethod.POST, RequestMethod.GET})
    public Result getUserAuthIds(AuthParam authParam) {
        return Result.success("查询成功", userAuthService.getUserAuthIds(authParam));
    }

}
